package com.woniuxy.tfss.websocket;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.woniuxy.tfss.entity.Message;
import com.woniuxy.tfss.entity.Order;
import com.woniuxy.tfss.entity.ResponseEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class SocketController {
    @Autowired
    private WebSocketServer webSocketServer;
    @Autowired
    private JacksonObjectMapper jacksonObjectMapper;

    @RequestMapping("/test")
    public String index() {
        return "test";
    }

    @RequestMapping("/send")
    @ResponseBody
    public Message send() throws JsonProcessingException {
        Order order=new Order();
        order.setSendInfo("天府五街");
        order.setRecInfo("孵化园");
        order.setNo("TFSS2020090910155837");
        // String msg=jacksonObjectMapper.writeValueAsString(order);
        webSocketServer.sendInfo("r3", new Message<>(901, order));
        webSocketServer.sendInfo("r3", new Message<>(902, order));
        webSocketServer.sendInfo("r3", new Message<>(907, order));
        webSocketServer.sendInfo("r3", new Message<>(908, order));
        webSocketServer.sendInfo("u1", new Message<>(903, order));
        webSocketServer.sendInfo("u1", new Message<>(904, order));
        webSocketServer.sendInfo("u1", new Message<>(905, order));
        webSocketServer.sendInfo("u1", new Message<>(906, order));

        // System.out.println(msg);
        return new Message<>(901, order);
    }
}
